package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.TravelQueryObject;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    private ITravelService TravelService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyThemeService strategyThemeService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        Page<Travel> page = TravelService.query(qo);
        model.addAttribute("page", page);
        return "travel/list";
    }

    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        return destinationService.list();
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Travel Travel) {
//        TravelService.saveOrUpdate(Travel);
        return JsonResult.success();
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep) {
        List<Destination> destinations = destinationService.getDestByDeep(deep);
        return destinations;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        TravelService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(String id, Integer state) {
        TravelService.audit(id, state);
        return JsonResult.success();
    }

    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(String id) {
        return JsonResult.success(TravelService.get(id).getContent());
    }


}
